<template>
<!--我的订单-->
  <div class="orders">
      <div class="titleWrap">
        <p class="titleName">客服</p>
      </div>
      <span v-if="questions">
        <ul class="noticeout">
          <li v-for="(question,index) in questions">
            <p class="noticeTitle font14">{{index + seq}}.{{question.questionTitle}}</p>
            <p class="noticeInfor font14">{{question.questionContent}}</p>
          </li>
        </ul>
        <div class="pageout"><Page :total="total" :current="pageNumber" :page-size="size" @on-change="changePage"/></div>
      </span>
      <span v-else>
        <nodata tip="暂时还没有常见问题哦~"></nodata>
      </span>
    <Spin fix v-show="isSpinShow" >
      <div class="loader">
        <Icon type="ios-loading" size=26 class="demo-spin-icon-load"></Icon>
        <div class="font14">加载中...</div>
      </div>
    </Spin>
  </div>
</template>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="less" rel="stylesheet/less">
  /* 旋转效果 */
  .demo-spin-icon-load{
    animation: ani-demo-spin 1s linear infinite;
  }
  @keyframes ani-demo-spin {
    from { transform: rotate(0deg);}
    50% { transform: rotate(180deg);}
    to { transform: rotate(360deg);}
  }
  /* 假如内容过长，一屏放不下，滚动条下拉覆盖不全 */
  .ivu-spin-fix {
    position: fixed;
  }

  .titleWrap {
    height: 40px;
    font-size: 18px;
    padding-bottom: 20px;
    text-align: justify-all;
    border-bottom: 1px solid #E1E1E1;
    margin-bottom: 20px;
    color: #957960;
    .titleName {
      float: left;
      line-height: 24px;
      border-bottom: 3px solid #957960;
      padding-bottom: 13px;
    }
  }
  .noticeout li {
    border-bottom: 1px solid #E1E1E1;
    padding: 20px 0;
    .noticeTitle, .noticeInfor {
      /*font-size: 16px;*/
      color: #333;
      line-height: 24px;
    }
    .noticeTitle {
      margin-bottom: 10px;
    }
  }
  .pageout {
    text-align: center;
    margin-top: 35px;
    height: 34px;
  }
  li:last-child{
    border-bottom: none;
  }
</style>
<script type="text/ecmascript-6">
  import nodata from '../template/null'
  import {issuePageWeb,centreInfoWeb} from '../../http'
    export default {
        name: 'kefu',
        props: {},
        data() {
            return {
              total:0,
              size:16,
              pageNumber:1,
              seq:1,
              questions:'',
              isSpinShow:false,
            };
        },
        methods: {
          //换页
          changePage(pageNumber) {
            this.pageNumber = pageNumber;
            this.seq = (this.pageNumber - 1) * this.size + 1;
            if(this.isSpinShow === false) {
              this.isSpinShow = true;
              //用户是否登录
              centreInfoWeb().then(res => {
                if (res.code === 200) {
                  //客服记录
                  issuePageWeb({pageNumber: this.pageNumber,pageSize:this.size}).then(res => {
                    if(res.code === 200) {
                      this.isSpinShow = false;
                      this.total = res.data.lists.total;
                      this.questions = res.data.lists.rows;
                    }else {
                      this.isSpinShow = false;
                      this.$Notice.warning({
                        title: "个人中心提醒",
                        desc: res.info,
                        duration: 3,
                      });
                    }
                  }).catch()
                } else {
                  this.isSpinShow = false;
                  this.$parent.$refs.loginInput.showModal()
                }
              }).catch()
            }
          },
          getKefu(){
            if(this.isSpinShow === false) {
              this.isSpinShow = true;
              //用户是否登录
              centreInfoWeb().then(res => {
                if (res.code === 200) {
                  //获取常见问题
                  issuePageWeb({pageNumber: this.pageNumber,pageSize:this.size}).then(res => {
                    if(res.code === 200) {
                      this.isSpinShow = false;
                      this.total = res.data.lists.total;
                      this.questions = res.data.lists.rows;
                      this.seq = (this.pageNumber - 1) * this.size + 1;
                    }else {
                      this.isSpinShow = false;
                      this.$Notice.warning({
                        title: "个人中心提醒",
                        desc: res.info,
                        duration: 3,
                      });
                    }
                  }).catch()
                }else {
                  this.isSpinShow = false;
                }
              }).catch()
            }
          }
        },
        created() {
          this.getKefu()
        },
        components: {
          nodata
        }
    }
</script>
